package com.atguigu.gmall.config;

import com.atguigu.gmall.interceptors.AuthInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

@Configuration  // 加入拦截器的整合类
public class WebMvcConfiguration extends WebMvcConfigurerAdapter {

    // @Autowired
    private AuthInterceptor authInterceptor;

    @Autowired
    public WebMvcConfiguration(AuthInterceptor authInterceptor){
        this.authInterceptor = authInterceptor;
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(authInterceptor).addPathPatterns("/**") // 默认拦截所有请求
                .excludePathPatterns("/error");  // 排除全局异常处理
        super.addInterceptors(registry);
    }
}
